/**
 * 
 */
package ui.model;

import java.text.NumberFormat;
import java.util.*;

import javax.swing.table.AbstractTableModel;

import model.*;

/**
 * @author Anthares
 *
 */
public class AppSettingsTableModel extends AbstractTableModel {
	private HashMap<AppSettingsEnum, AppSettings> content;
	private ArrayList<String> columnNames = new ArrayList<String>();
	
	public AppSettingsTableModel(){
		content = AppSettings.getSettings();
		columnNames.add("Setting");
		columnNames.add("Value");
	}
	
	/* (non-Javadoc)
	 * @see javax.swing.table.TableModel#getColumnCount()
	 */
	@Override
	public int getColumnCount() {
		// TODO Auto-generated method stub
		return columnNames.size();
	}

	/* (non-Javadoc)
	 * @see javax.swing.table.TableModel#getRowCount()
	 */
	@Override
	public int getRowCount() {
		// TODO Auto-generated method stub
		return content.size();
	}
	
	public String getColumnName(int col){
		return columnNames.get(col);
	}

	/* (non-Javadoc)
	 * @see javax.swing.table.TableModel#getValueAt(int, int)
	 */
	@Override
	public Object getValueAt(int row, int col) {
		AppSettings apps = content.get(AppSettingsEnum.valueOf(row));
		NumberFormat nf = NumberFormat.getCurrencyInstance();
		switch(col){
		case 0 : return apps.getName();
		case 1 : return nf.format(apps.getValue());
		default : return null;
		}
	}
	public Class getColumnClass(int col){
		return String.class;
	}
	public AppSettings getElementAt(int index){
		return content.get(AppSettingsEnum.valueOf(index));
	}
}
